Debugging OneMore
Sunday, February 19, 2023
9:40 AM
There are two ways to attach the Visual Studio debugger to OneMore. You can either force a break point or attach to a running instance.
Inject A Debugger Break Point
The first is to instrument the source code by adding a call to the Debugger.Launch method where you want to start the debugger
System.Diagnostics.Debugger.Launch();
This will cause Visual Studio to launch the Attach Debugger dialog. This is most useful when you already have the OneMore solution open in Visual Studio so you can attach using that VS instance with all of the source code and symbols ready to go.
If the Attach Debugger dialog does not appear and instead a new instance of VS is opened then check this out from Microsoft about the Just in Time Debugger settings.
Attach to A Running Instance
Alternatively, you can attach the Visual Studio debugger directly to the running OneMore process. OneMore runs in a process named dllhost, of which there are many. There are two ways to identify which instance is the OneMore process.
Use the Log File
Look in the OneMore log file. The process ID is stated in the first line of each session in the log; this is the line beginning with "Starting dllhost".
Starting dllhost 19712, ...
Use Task Manager
Open Task Manager and add the column named "Command Line". Look for the dllhost process with this command line
C:\WINDOWS\system32\DllHost.exe /Processid:{88AB88AB-CDFB-4C68-9C3A-F10B75A5BC61}
Terminate A Running Instance
There are times when the COM Surrogate process will not release resources, causing it to hang and remain in-process even if OneNote is stopped. You can terminate this process, dllhost, in one of two ways.
Use the Process ID
As mentioned above, the process ID is reported in the first line of each session in the log file. Stop the process from Task Manager or use the taskkill command
taskkill /pid <pid> /f
Use the stop.ps1 Script
An easier solution is to use the provided stop script to forcefully terminate the dllhost process and OneNote. This is located in the OneMore solution directory. Run this from an administrative PowerShell window
.\stop.ps1
Enable OneNote Add-in Interface Error Reporting
Normally, OneNote captures and supressed user interface errors from add-ins. This means there may be error in your add-in that are occurring but there is no indication that they are happening. These can be fixed but only if you know about them.
Open the OneNote options dialog, click the Advanced tab, and scroll to the bottom of the page. Enable the Show add-in user interface errors.
When an error occurs, OneNote will display a dialog showing the add-in method name that caused the error.
COM Timeouts
The OneNote IApplication COM object will timeout if not used within a reasonable window (somewhere around a minute perhaps?) and, regardless of whether you've wrapped the call in a try/catch, OneNote will abort the call, display a dialog, and possibly leave OneNote in an unusable state. This can adversely affect a long-running debugging session. But in normal operations, OneMore makes every effort to minimize how long it holds on to an Application instance.
#omwiki #omdeveloper
© 2020 Steven M Cohn. All rights reserved.
Please consider a sponsorship or one-time donation to support ongoing development
Created with OneNote.